<?php
declare (strict_types = 1);
namespace app\admin\controller;

use think\Request;
use think\facade\{View};
use think\exception\ValidateException;

use app\common\model\{AboutUs};
use app\common\validate\{AboutUsValidate};

/** 介绍视频 */
class AboutUsController extends BaseController
{
    private $aboutUsModel;
    public function __construct(AboutUs $aboutUsModel)
    {
        parent::initialize();
        $this->aboutUsModel = $aboutUsModel;
    }

    /** 渲染视频修改页面 */
    public function about_us_edit()
    {
        $info = $this->aboutUsModel->getFind(['id' => 1]);

        View::assign('info', $info['data']);
        return view();
    }

    /** 修改视频列表 */
    public function about_us_data()
    {
        $data = input('');

        try{
            validate(AboutUsValidate::class)->scene('add')->check($data);
        }catch(ValidateException $e){
            $this->error_back($e->getError());
        }

        $data['id'] = 1;

        $flag = $this->aboutUsModel->edit($data);

        if($flag['code'] != 'ok'){
            $this->error_back($flag['msg']);
        }

        $this->success_back('编辑成功');
    }

    /**
     * 视频分片上传
     */
    public function video_adds(){
        $uploadDir = app()->getRootPath() . 'public/storage/video/' . date('Ymd');
        $upload = new Upload(
            $_FILES['file']['tmp_name'],
            $_POST['blob_num'],
            $_POST['total_blob_num'],
            $_POST['file_name'],
            $uploadDir
        );
    
        $upload->apiReturn();
    }
}
